/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        network_service.h
// Purpose:     network service
// Author:      syy
// Modified by: 
// Created:     2014/5/13 13:27
// RCS-ID:      
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#ifndef _INETWORKSERVICE_H_
#define _INETWORKSERVICE_H_

#include "qbnet.h"
#include "core/common_types.h"
#include "core/comdefs.h"
#include "qbprotocol/include/message_process_data.h"

// {20994F3B-CCA2-41a2-9F44-DCF60B78D3C4}
DEFINE_GUID(CLSID_NetworkService, 
			0x20994f3b, 0xcca2, 0x41a2, 0x9f, 0x44, 0xdc, 0xf6, 0xb, 0x78, 0xd3, 0xc4);


// {517807F4-A60F-4aca-AB77-A40331E78DF2}
DEFINE_GUID(IID_INetworkService, 
			0x517807f4, 0xa60f, 0x4aca, 0xab, 0x77, 0xa4, 0x3, 0x31, 0xe7, 0x8d, 0xf2);

#ifdef _MSC_VER
extern "C" S_QBNET_EXPORT HRESULT __stdcall QtDllGetClassObject(REFCLSID rclsid,
																REFIID riid,
																LPVOID * ppv);
#else
STDAPI NetworkService_CreateObject(REFCLSID rclsid,
                                   REFIID riid,
                                   LPVOID* ppv);
#endif

#ifdef __cplusplus
extern "C" {
#endif

	DECLARE_INTERFACE(INetworkServiceObserver/*, IUnknown*/)
	{
		STDMETHOD_(bool,OnConnect) (THIS_ int32_t connect_id,int32_t error_id) PURE;
        STDMETHOD_(void,OnReceive) (THIS_ int32_t connect_id,MESSAGE_SHARED_PTR msp) PURE;
        STDMETHOD_(void,OnReceive2) (THIS_ int32_t connect_id,const char* buff,uint32_t bytes) PURE;
		STDMETHOD_(void,OnFailed) (THIS_ int32_t connect_id, int32_t error_id) PURE;
	};

	DECLARE_INTERFACE(INetworkEventObserver/*, IUnknown*/)
	{
		STDMETHOD_(void,OnForceQuit) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(void,OnDisConnect) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(void,OnRecover) (THIS_ int32_t connect_id) PURE;
	};

	DECLARE_INTERFACE_(INetworkService, IUnknown)
	{
		STDMETHOD_(int32_t,CreateSocket) (THIS_ qb::SocketType sock_type) PURE;
		STDMETHOD_(int32_t,DestorySocket) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,Connect) (THIS_ int32_t connect_id,const char* ipAddress, uint16_t port) PURE;
		STDMETHOD_(int32_t,Disconnect) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,DisconnectAll) (THIS_) PURE;
		STDMETHOD_(int32_t,Send) (THIS_ int32_t connect_id, const char* buff,uint32_t bytes) PURE;
		STDMETHOD_(int32_t,NotifyForceQuit) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,NotifyDisconnect) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,NotifyRecover) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(int32_t,RegisterNetworkServiceObserver) (THIS_ int32_t connect_id, INetworkServiceObserver* observer) PURE;
		STDMETHOD_(int32_t,DeRegisterNetworkServiceObserver) (THIS_ int32_t connect_id, INetworkServiceObserver* observer) PURE;
		STDMETHOD_(int32_t,RegisterNetworkEventObserver) (THIS_ INetworkEventObserver* observer) PURE;
		STDMETHOD_(int32_t,DeRegisterNetworkEventObserver) (THIS_ INetworkEventObserver* observer) PURE;
		STDMETHOD_(int32_t,SetProxy) (THIS_ 
			int32_t proxy_type,
			const char* proxy_host,
			uint16_t proxy_port,
			const char* username,
			const char* password,
			const char* domain) PURE;
        STDMETHOD_(int32_t,ProxyTest) (THIS_
            int32_t proxy_type,
            const char* dst_host,
            uint16_t dst_port,
            const char* proxy_host,
            uint16_t proxy_port,
            const char* username,
            const char* password,
            const char* domain) PURE;
		STDMETHOD_(uint32_t,GetTargetIP) (THIS_ int32_t connect_id) PURE;
		STDMETHOD_(uint16_t,GetTargetPort) (THIS_ int32_t connect_id) PURE;
	};

#ifdef __cplusplus
}
#endif

#endif // _INETWORKSERVICE_H_
